import urllib

import execjs
import requests


headers = {
    "accept": "application/json, text/plain, */*",
    "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,ar;q=0.7",
    "cache-control": "no-cache",
    "pragma": "no-cache",
    "priority": "u=1, i",
    "referer": "https://www.douyin.com/user/MS4wLjABAAAAUAIruJgVtNypQalGNrwUoy-4R-HwPBoiGUbgCWuYX8vSERBvm5SoR3gafR59VN-W?from_tab_name=main",
    "sec-ch-ua": "\"Chromium\";v=\"140\", \"Not=A?Brand\";v=\"24\", \"Microsoft Edge\";v=\"140\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin",
    "uifid": "d4579b5b1721ffdd22d8a6ff378781159e3b4e5a1248a83fc8c708ec2606b705c55e418f00ac63d7cf11eec8e42b3216af21d0a56129cec84cda8c1492358f3d9587fb918391e8fe9813c4b75b6689535818f807e9c461b66d15d64b6461a1efa4219cda0c11670520e24d0911c010ae468b1b0e6105bd581b71e1e3875c86b36ba7095a8199d595f6194b81728a42739e90736ee95ff577f1723ea42fb8bf98",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0"
}
cookies = {
    "volume_info": "%7B%22volume%22%3A0.6%7D",
    "xgplayer_user_id": "633757564182",
    "live_use_vvc": "%22false%22",
    "enter_pc_once": "1",
    "UIFID_TEMP": "d4579b5b1721ffdd22d8a6ff378781159e3b4e5a1248a83fc8c708ec2606b705e7026a41a256323e32a331dd71369cb1c4b92016e36dfdf5fcd9c7539a7015c906515b4e4a96cee4a9163a5796298d4f",
    "hevc_supported": "true",
    "fpk1": "U2FsdGVkX1+QXY9Pk3IDO+yuh5yDh7L3YovWnhOywkhIs49Sv/6FAS0hcfCd5Jt6jRkSShzXaOpL/OEQPogEnA==",
    "fpk2": "d2ad6785d256851dd366703bdc61aa61",
    "bd_ticket_guard_client_web_domain": "2",
    "UIFID": "d4579b5b1721ffdd22d8a6ff378781159e3b4e5a1248a83fc8c708ec2606b705c55e418f00ac63d7cf11eec8e42b3216af21d0a56129cec84cda8c1492358f3d9587fb918391e8fe9813c4b75b6689535818f807e9c461b66d15d64b6461a1efa4219cda0c11670520e24d0911c010ae468b1b0e6105bd581b71e1e3875c86b36ba7095a8199d595f6194b81728a42739e90736ee95ff577f1723ea42fb8bf98",
    "SEARCH_RESULT_LIST_TYPE": "%22single%22",
    "s_v_web_id": "verify_mfq6kya5_UMF6zUId_XrxP_4YIG_8QEz_RcHRM9wAoO2S",
    "passport_csrf_token": "360e17d19a931a32b345e68b218fb93b",
    "passport_csrf_token_default": "360e17d19a931a32b345e68b218fb93b",
    "__security_mc_1_s_sdk_crypt_sdk": "9ed305e0-47b8-ab60",
    "__security_mc_1_s_sdk_cert_key": "5f9d7bd6-42c7-957b",
    "douyin.com": "",
    "xg_device_score": "7.694897303211912",
    "device_web_cpu_core": "16",
    "device_web_memory_size": "8",
    "architecture": "amd64",
    "dy_swidth": "1920",
    "dy_sheight": "1080",
    "stream_recommend_feed_params": "%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A1920%2C%5C%22screen_height%5C%22%3A1080%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A16%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A10%2C%5C%22effective_type%5C%22%3A%5C%224g%5C%22%2C%5C%22round_trip_time%5C%22%3A50%7D%22",
    "strategyABtestKey": "%221758862141.652%22",
    "passport_mfa_token": "CjcUR0T9R%2BP7d3RLRlco%2BZvvT5hc%2FSBfqiVD4FzH6cf6P9rEZsyno%2B%2FDS05ggWvTm77SyEftpV7JGkoKPAAAAAAAAAAAAABPhWn3xQ64oZZUGFnNs%2FdSCtuybmoslR3zbTU9HITCaW%2BkW7ninEHDfou0meXhMr44HRDkmP0NGPax0WwgAiIBA%2FBoEYk%3D",
    "d_ticket": "31a49e424cbd9674c6d615746f5491bb425f5",
    "passport_assist_user": "CkFRqjPIiLv7MJUNuh_VF4iZocAXwe5Dpho97P_2amjzM-bTKGZdo1oIT683kktF-zZtmtQpb3t56_KV0jlulan2VxpKCjwAAAAAAAAAAAAAT4Wv_dX9Rkmbg3G4C2jV_FWAiY0MrweZuLGJnz7PHUHwu6-IWp06wvUyluLgVm3BlEsQuJn9DRiJr9ZUIAEiAQPYI1-X",
    "n_mh": "tOBF_KNaVpFbxj7TWl7PfnsN6W2AIx2kGVG969wbJhs",
    "sid_guard": "f41dc4ff3c9a470f2b10abb97284798d%7C1758862528%7C5183999%7CTue%2C+25-Nov-2025+04%3A55%3A27+GMT",
    "uid_tt": "1c41c79327c36eed6a47625cce53ec38",
    "uid_tt_ss": "1c41c79327c36eed6a47625cce53ec38",
    "sid_tt": "f41dc4ff3c9a470f2b10abb97284798d",
    "sessionid": "f41dc4ff3c9a470f2b10abb97284798d",
    "sessionid_ss": "f41dc4ff3c9a470f2b10abb97284798d",
    "session_tlb_tag": "sttt%7C16%7C9B3E_zyaRw8rEKu5coR5jf________-f5vR9Kq8L5IGM_PP_I0je3o2R5-9K_KjJunw3SapWPDQ%3D",
    "is_staff_user": "false",
    "sid_ucp_v1": "1.0.0-KGVlOTFlYThhZjk1MGZlN2E4MWY5ZmE5MGFiM2JlN2U3NDU1Y2Q0ZTUKIQiQ94Ci1MyxBhDAudjGBhjvMSAMMIaJ0bIGOAdA9AdIBBoCbHEiIGY0MWRjNGZmM2M5YTQ3MGYyYjEwYWJiOTcyODQ3OThk",
    "ssid_ucp_v1": "1.0.0-KGVlOTFlYThhZjk1MGZlN2E4MWY5ZmE5MGFiM2JlN2U3NDU1Y2Q0ZTUKIQiQ94Ci1MyxBhDAudjGBhjvMSAMMIaJ0bIGOAdA9AdIBBoCbHEiIGY0MWRjNGZmM2M5YTQ3MGYyYjEwYWJiOTcyODQ3OThk",
    "login_time": "1758862527187",
    "_bd_ticket_crypt_cookie": "d1a29b1758ee2ec5927d44241f5c5a44",
    "__security_mc_1_s_sdk_sign_data_key_web_protect": "9bd54fec-4b3d-acb3",
    "__security_server_data_status": "1",
    "publish_badge_show_info": "%220%2C0%2C0%2C1758862527739%22",
    "DiscoverFeedExposedAd": "%7B%7D",
    "SelfTabRedDotControl": "%5B%5D",
    "FOLLOW_NUMBER_YELLOW_POINT_INFO": "%22MS4wLjABAAAAVi8PClZjQkH4_9SXPKYTSX0xavhYtXpuorO_LcZygH86bvQKIXxs4XyZx6QP2-B2%2F1758902400000%2F0%2F1758862531102%2F0%22",
    "bd_ticket_guard_client_data": "eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWl0ZXJhdGlvbi12ZXJzaW9uIjoxLCJiZC10aWNrZXQtZ3VhcmQtcmVlLXB1YmxpYy1rZXkiOiJCTmlYaGVyTEQxeXhFL1ZuSlVjRWhNaFRBdVUyQ0M2SElNMWtZMW0raUUrRnIyTk5BWnlTSEp3V1JFMkI0QWdPSU1JTC9HWjh6S3hzeW5US0tyL29TdFk9IiwiYmQtdGlja2V0LWd1YXJkLXdlYi12ZXJzaW9uIjoyfQ%3D%3D",
    "ttwid": "1%7CVdGDY2q6ockgwawSYBKgGj8p67yQk1IkLiW--KwO8F8%7C1758862537%7Cd80c9cd0f59fe176697c82e3996dcee5c8b6c9efacc2a651c80e00c6bf641219",
    "biz_trace_id": "f04cf5ae",
    "odin_tt": "03d780fdbb3f53d2b3b2348dffe99af4676c5e65612ceba86720e1704d542c76fbfb78c1a7606eebe4c32072a377fd9bdf21d76cd096d88978f8e670df3e29db",
    "my_rd": "2",
    "FOLLOW_LIVE_POINT_INFO": "%22MS4wLjABAAAAVi8PClZjQkH4_9SXPKYTSX0xavhYtXpuorO_LcZygH86bvQKIXxs4XyZx6QP2-B2%2F1758902400000%2F0%2F1758862551557%2F0%22",
    "download_guide": "%222%2F20250926%2F0%22",
    "is_dash_user": "1",
    "__ac_nonce": "068d61e0f00377a305c36",
    "__ac_signature": "_02B4Z6wo00f01lB8xVgAAIDDKpUxvr.lqxpQXMHAAPzYa8",
    "home_can_add_dy_2_desktop": "%220%22",
    "IsDouyinActive": "true"
}
params = {
    "device_platform": "webapp",
    "aid": "6383",
    "channel": "channel_pc_web",
    "sec_user_id": "MS4wLjABAAAAUAIruJgVtNypQalGNrwUoy-4R-HwPBoiGUbgCWuYX8vSERBvm5SoR3gafR59VN-W",
    "max_cursor": "0",
    "locate_query": "false",
    "show_live_replay_strategy": "1",
    "need_time_list": "1",
    "time_list_query": "0",
    "whale_cut_token": "",
    "cut_version": "1",
    "count": "18",
    "publish_video_strategy_type": "2",
    "from_user_page": "1",
    "update_version_code": "170400",
    "pc_client_type": "1",
    "pc_libra_divert": "Windows",
    "support_h265": "1",
    "support_dash": "1",
    "cpu_core_num": "16",
    "version_code": "290100",
    "version_name": "29.1.0",
    "cookie_enabled": "true",
    "screen_width": "1920",
    "screen_height": "1080",
    "browser_language": "zh-CN",
    "browser_platform": "Win32",
    "browser_name": "Edge",
    "browser_version": "140.0.0.0",
    "browser_online": "true",
    "engine_name": "Blink",
    "engine_version": "140.0.0.0",
    "os_name": "Windows",
    "os_version": "10",
    "device_memory": "8",
    "platform": "PC",
    "downlink": "10",
    "effective_type": "4g",
    "round_trip_time": "50",
    "webid": "7522003828189218347",
    "uifid": "d4579b5b1721ffdd22d8a6ff378781159e3b4e5a1248a83fc8c708ec2606b705c55e418f00ac63d7cf11eec8e42b3216af21d0a56129cec84cda8c1492358f3d9587fb918391e8fe9813c4b75b6689535818f807e9c461b66d15d64b6461a1efa4219cda0c11670520e24d0911c010ae468b1b0e6105bd581b71e1e3875c86b36ba7095a8199d595f6194b81728a42739e90736ee95ff577f1723ea42fb8bf98",
    "verifyFp": "verify_mfq6kya5_UMF6zUId_XrxP_4YIG_8QEz_RcHRM9wAoO2S",
    "fp": "verify_mfq6kya5_UMF6zUId_XrxP_4YIG_8QEz_RcHRM9wAoO2S",
    "msToken": "b7Ea0drlITXxRZuQasTxVSYtbykYl7LQzpRuHAB3gSREdgwNCS795fHhL9cFQxW16AOqojPgOkXIOabq11ta4WnwfiXYTVLHrT0EsM34-wN6rQ7vg6o4vG3aGBt1cayEupf9pnVz0Zl0cwS3153dWAgXOdNmC9m35jEql8U98Wy_",
    "a_bogus": "Qj0RgHWLEdQncd/GYcr7eS-lZMo/Ns8ygaTORulTHOFicH0YbYNVgNS2jxwE4gDmlSBThe37nd0lbxVcssUsZorpqmkvSYJyUz2V9z0Lhqh3bBk27qmieGGEFiPG0W4Yu5I9i2R5ls0FIx5WVrCzAd3Hw/vNm5DdBq3vVMznT9Ks0ASjwx/ca-SkYhkq4E=="
}
fp = execjs.compile(open("verifyFp.js",'r').read()).call("fp")

params['verifyFp'] = fp
params['fp'] = fp
print(fp)
encode_params_string = urllib.parse.urlencode(params,safe="=")
url = 'https://www.douyin.com/aweme/v1/web/aweme/post/?' + encode_params_string
print(url)
a_bogus = execjs.compile(open("main.js",'r',encoding="utf-8").read()).call("get_abgous",url)
print(a_bogus)

params['a_bogus'] = a_bogus
response = requests.get(url, headers=headers, cookies=cookies, params=params,proxies={
    "http": "http://127.0.0.1:7890",
    "https": "http://127.0.0.1:7890"
})
with open("user_list.json","w",encoding="utf-8") as f:
    f.write(response.text)
print(response.text)
print(response)